﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using FRMS.Model;

namespace FRMS.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class miniprogram : Controller
    {
        //private readonly IOptions<wx_key> _ConfigSettingt;
        //public miniprogram(IOptions<wx_key> ConfigSetting)
        //{
        //    _ConfigSettingt = ConfigSetting;
        //}

        //public IActionResult Index()
        //{
        //    var appid = _ConfigSettingt.Value.AppID;
        //    var secret = _ConfigSettingt.Value.Secret;
        //    return View();

        //}


        #region 微信小程序获取openID
        [HttpPost]
        [Route("GetopenID")]
        public ResponseMessage GetopenID(wx_openid code)
        {
            // Console.WriteLine(code.js_code);
            string js_code = code.js_code;
            ResponseMessage result = new ResponseMessage();//"wx5f81a3bc2633bc18"   "4fcac9f0c5fd0575fc45f45a54bced5d"

            string serviceAddress = "https://api.weixin.qq.com/sns/jscode2session?appid=wx5f81a3bc2633bc18&secret=4fcac9f0c5fd0575fc45f45a54bced5d&js_code=" + js_code + "&grant_type=authorization_code";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress);
            request.Method = "GET";
            request.ContentType = "text/html;charset=utf-8";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, System.Text.Encoding.UTF8);
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();
            var obj = new
            {
                data = retString,
                IsSuccess = true,

            };
            JObject jo = JObject.Parse(retString);
            string sessionKey = jo["session_key"].ToString();
            string openid = jo["openid"].ToString();
            result.errcode = 0;
            result.errmsg = "";
            result.data = openid;
            result.total = 0;
            return result;
        }

        #endregion


        #region 微信小程序解密后获取手机号
        [HttpPost]
        [Route("GetphoneString")]
        public ResponseMessage GetphoneString(wx_encryptedData wx_code)
        {
            string openid = "";
            string phone = "";
            ResponseMessage result = new ResponseMessage();
            if (wx_code.json_code == null || wx_code.iv == null || wx_code.encryptedData == null)
            {
                result.errcode = 1;
                result.errmsg = "授权失败";
                result.data = "";
                result.total = 0;
                return result;
            }
            //ros ro = new ros();
            //wx_encryptedData wx_code = new wx_encryptedData();
            //ResponseMessage result = new ResponseMessage();
            //HttpContext context=null;
            //HttpRequest request1 = context.Request;
            //string a = request1.Body.ToString();
            //string ss = Request.Form["name_c"].ToString()
            //wx_code.json_code = Request.Form["json_code"];
            //wx_code.iv = Request.Form["iv"];
            //wx_code.encryptedData = Request.Form["encryptedData"];
            string iv = wx_code.iv;
            string text = wx_code.encryptedData;
            string serviceAddress = "https://api.weixin.qq.com/sns/jscode2session?appid=wx5f81a3bc2633bc18&secret=4fcac9f0c5fd0575fc45f45a54bced5d&js_code=" + wx_code.json_code + "&grant_type=authorization_code";
            //string serviceAddress = "https://api.weixin.qq.com/sns/jscode2session?appid=" + "wx5f81a3bc2633bc18" + "&secret="
            //    + "4fcac9f0c5fd0575fc45f45a54bced5d" + "&js_code=" + wx_code.json_code + "&grant_type=authorization_code";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress);
            request.Method = "GET";
            request.ContentType = "text/html;charset=utf-8";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, System.Text.Encoding.UTF8);
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();
            var obj = new
            {
                data = retString,
                IsSuccess = true,

            };

            JObject jo = JObject.Parse(retString);
            string sessionKey = jo["session_key"].ToString();
            openid = jo["openid"].ToString();
            if (!string.IsNullOrEmpty(sessionKey) && !string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(iv))
            {
                // 传输的数据有变化，必须处理，不然FromBase64String 报错
                text = text.Replace("%", "").Replace(",", "").Replace(" ", "+");
                sessionKey = sessionKey.Replace("%", "").Replace(",", "").Replace(" ", "+");
                iv = iv.Replace("%", "").Replace(",", "").Replace(" ", "+");
                string result2 = "";

                using (Aes aesAlg = Aes.Create())
                {
                    try
                    {
                        aesAlg.Key = Convert.FromBase64String(sessionKey);
                        aesAlg.IV = Convert.FromBase64String(iv);
                        aesAlg.Mode = CipherMode.CBC;
                        aesAlg.Padding = PaddingMode.PKCS7;
                        //aesAlg.BlockSize = 128; //这里记得千万不安装官网的说明加上，不然解析出乱码
                        ICryptoTransform decryptor = aesAlg.CreateDecryptor();

                        // Create the streams used for decryption.
                        using (MemoryStream msDecrypt = new MemoryStream(Convert.FromBase64String(text)))
                        {
                            using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                            {
                                using (StreamReader srDecrypt = new StreamReader(csDecrypt))
                                {
                                    result2 = srDecrypt.ReadToEnd();
                                    JObject json3 = (JObject)JsonConvert.DeserializeObject(result2);
                                    phone = json3["purePhoneNumber"].ToString();
                                    //result.data = phone;
                                    //if (json3["purePhoneNumber"] != null)
                                    //{
                                    //    phone = json3["purePhoneNumber"].ToString(),
                                    //    ro.code = "0";
                                    //    ro.data = new
                                    //    {
                                    //        phone = json3["purePhoneNumber"].ToString(),
                                    //        openid = openid
                                    //    };
                                    //    return Json(ro);
                                    //}
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        //ro.code = "4";
                        //ro.msg = "系统异常！";
                        //if (aesAlg != null)
                        //    aesAlg.Clear();
                    }
                    finally
                    {
                        if (aesAlg != null)
                            aesAlg.Clear();
                    }

                }
            }
            wx_info lst = new wx_info();
            result.errcode = 0;
            result.errmsg = "登录成功";

            lst.openid = openid;
            lst.phone = phone;
            result.data = lst;
            result.total = 0;
            return result;
        }
        #endregion

        #region 微信小程序获取access_token
        [HttpPost]
        [Route("Getaccess_token")]
        public ResponseMessage Getaccess_token()
        {

            ResponseMessage result = new ResponseMessage();

            //string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + "wx5f81a3bc2633bc18" + "&secret="
            //    + "4fcac9f0c5fd0575fc45f45a54bced5d";
            string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx5f81a3bc2633bc18&secret=4fcac9f0c5fd0575fc45f45a54bced5d";
            string serviceAddress = url;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress);
            request.Method = "GET";
            request.ContentType = "textml;charset=UTF-8";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8);
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();
            wx_access_token lst = new wx_access_token();
            try
            {
                JObject jo = JObject.Parse(retString);
                string access_token = jo["access_token"].ToString();
                int expires_in = int.Parse(jo["expires_in"].ToString());
                //string access_token = jo["access_token"].ToString();

                result.errcode = 0;
                result.errmsg = "";

                lst.access_token = access_token;
                lst.expires_in = expires_in;
                result.data = lst;
                result.total= 0;
                return result;
            }
            catch (Exception ex)
            {

                result.errcode = 1;
                result.errmsg = "获取失败";

                //lst.openid = openid;
                //lst.phone = phone;
                result.data = lst;
                result.total = 0;
                return result;
            }
        }

        #endregion

        //#region 微信小程序发送消息
        //[HttpPost]
        //[Route("PostMessageInfo1")]
        //public ResponseMessage PostMessageInfo(wx_postmessage wx_message)
        //{

        //    ResponseMessage result = new ResponseMessage();

        //    string url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={0}" + wx_message.access_token;
        //    HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(url);
        //    wReq.Method = "Post";
        //    //wReq.ContentType = "application/json";
        //    //wReq.ContentType = "application/x-www-form-urlencoded";
        //    wReq.ContentType = "application/json";
        //    string jsonParam = JsonConvert.SerializeObject(wx_message.value);
        //    //byte[] data = Encoding.Default.GetBytes(HttpUtility.UrlEncode("key=rfwreewr2332322232&261=3&261=4"));
        //    byte[] data = System.Text.Encoding.UTF8.GetBytes(jsonParam);
        //    wReq.ContentLength = data.Length;
        //    Stream reqStream = wReq.GetRequestStream();
        //    reqStream.Write(data, 0, data.Length);
        //    reqStream.Close();
        //    string result1 = "";
        //    using (StreamReader sr = new StreamReader(wReq.GetResponse().GetResponseStream()))
        //    {
        //        result1 = sr.ReadToEnd();


        //    }
        //    try
        //    {
        //        //JObject jo = JObject.Parse(retString);
        //        //string access_token = jo["access_token"].ToString();
        //        //int expires_in = int.Parse(jo["expires_in"].ToString());
        //        //string access_token = jo["access_token"].ToString();

        //        result.errcode = 0;
        //        result.errmsg = "";

        //        //lst.access_token = access_token;
        //        //lst.expires_in = expires_in;
        //        result.data = result1;
        //        result.totalrecords = 0;
        //        return result;
        //    }
        //    catch (Exception ex)
        //    {

        //        result.errcode = 1;
        //        result.errmsg = "获取失败";

        //        //lst.openid = openid;
        //        //lst.phone = phone;
        //        result.data = "";
        //        result.totalrecords = 0;
        //        return result;
        //    }
        //}


        //public ResponseMessage PostMessageInfo(wx_postmessage wx_message)
        //{
        //    //AjaxResult res = new AjaxResult();
        //    //res.state = false;
        //    var responseString = "";
        //    ResponseMessage result = new ResponseMessage();
        //    try
        //    {
        //        //AccessTokenModel AccessTokenModel = xcx_Get_Token();//获取access_token
        //        string _url = string.Format("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={0}", wx_message.access_token);
        //        //json参数
        //        string jsonParam = Newtonsoft.Json.JsonConvert.SerializeObject(new
        //        {
        //            touser = wx_message.touser,   //"o1nvI5Nngrq2hUI_17jue-erLplc",//用戶openid
        //            template_id = "kkKUHjxPI-FRZ8Suz-yEkhLP8gj_zppsythKaMh4Y0c",    // 模版template_id
        //            page = wx_message.page,//"../visitorpetition/petition",
        //            //miniprogram_state = "developer",
        //            lang = "zh_CN",
        //            data = new
        //            {
        //                name1 = new { value = wx_message.name1.ToString() },
        //                time2 = new { value = wx_message.time2.ToString() },//DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")
        //                thing3 = new { value = wx_message.thing3.ToString() },
        //                phone_number8 = new { value = wx_message.phone_number8.ToString() },
        //                phrase10 = new { value = wx_message.phrase10.ToString() },
        //            }
        //        });
        //        //string jsonParam = Newtonsoft.Json.JsonConvert.SerializeObject(new
        //        //{
        //        //    touser = "o1nvI5Nngrq2hUI_17jue-erLplc",//用戶openid
        //        //    template_id = "kkKUHjxPI-FRZ8Suz-yEkhLP8gj_zppsythKaMh4Y0c",    // 模版template_id
        //        //    page = "../visitorpetition/petition",
        //        //    //miniprogram_state = "developer",
        //        //    lang = "zh_CN",
        //        //    data = new
        //        //    {
        //        //        name1 = new { value = "张飞" },
        //        //        time2 = new { value = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") },//DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")
        //        //        thing3 = new { value = "测试" },
        //        //        phone_number8 = new { value = "18768176955" },
        //        //        phrase10 = new { value = "新月小区" },
        //        //    }
        //        //});
        //        var request = (HttpWebRequest)WebRequest.Create(_url);
        //        request.Method = "POST";
        //        request.ContentType = "application/json;charset=UTF-8";
        //        byte[] byteData = Encoding.UTF8.GetBytes(jsonParam);
        //        int length = byteData.Length;
        //        request.ContentLength = length;
        //        Stream writer = request.GetRequestStream();
        //        writer.Write(byteData, 0, length);
        //        writer.Close();
        //        var response = (HttpWebResponse)request.GetResponse();
        //        responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();


        //        //JavaScriptSerializer js = new JavaScriptSerializer();   //实例化一个能够序列化数据的类
        //        //AccessTokenModel_Err ErrInfo = js.Deserialize<AccessTokenModel_Err>(responseString);


        //        //AccessTokenModel_Err ErrInfo = (AccessTokenModel_Err)JsonConvert.DeserializeObject(responseString);
        //        //res.message = ErrInfo.errmsg;
        //        //if (ErrInfo.errcode == 0)
        //        //    res.state = true;
        //        //return responseString.ToString();
        //        result.errcode = 0;
        //        result.errmsg = "";

        //        //lst.access_token = access_token;
        //        //lst.expires_in = expires_in;
        //        result.data = responseString;
        //        result.totalrecords = 0;
        //        return result;
        //    }
        //    catch (Exception ex)
        //    {
        //        result.errcode = 0;
        //        result.errmsg = "";

        //        //lst.access_token = access_token;
        //        //lst.expires_in = expires_in;
        //        result.data = responseString;
        //        result.totalrecords = 0;
        //        return result;
        //    }
        //    //return Json(res, JsonRequestBehavior.AllowGet);
        //}

        //访客到访申请审核通知
        //public ResponseMessage PostMessageInfo1(wx_postmessage wx_message)
        //{
        //    //AjaxResult res = new AjaxResult();
        //    //res.state = false;
        //    var responseString = "";
        //    ResponseMessage result = new ResponseMessage();
        //    try
        //    {
        //        //AccessTokenModel AccessTokenModel = xcx_Get_Token();//获取access_token
        //        string _url = string.Format("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={0}", wx_message.access_token);
        //        //json参数
        //        string jsonParam = Newtonsoft.Json.JsonConvert.SerializeObject(new
        //        {
        //            touser = wx_message.touser,   //"o1nvI5Nngrq2hUI_17jue-erLplc",//用戶openid
        //            template_id = "cUVb5_l7SNZ75MX62peTrY-My6ozsM45i1pQGk9SDpc",    // 模版template_id
        //            page = wx_message.page,//"../visitorpetition/petition",
        //            //miniprogram_state = "developer",
        //            lang = "zh_CN",
        //            data = new
        //            {
        //                name1 = new { value = wx_message.name1.ToString() },
        //                time2 = new { value = wx_message.time2.ToString() },//DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")
        //                phrase3 = new { value = wx_message.phrase3.ToString() },
        //                phone_number6 = new { value = wx_message.phone_number6.ToString() },
        //                thing11 = new { value = wx_message.thing11.ToString() },
        //            }
        //        });
        //        //string jsonParam = Newtonsoft.Json.JsonConvert.SerializeObject(new
        //        //{
        //        //    touser = "o1nvI5Nngrq2hUI_17jue-erLplc",//用戶openid
        //        //    template_id = "kkKUHjxPI-FRZ8Suz-yEkhLP8gj_zppsythKaMh4Y0c",    // 模版template_id
        //        //    page = "../visitorpetition/petition",
        //        //    //miniprogram_state = "developer",
        //        //    lang = "zh_CN",
        //        //    data = new
        //        //    {
        //        //        name1 = new { value = "张飞" },
        //        //        time2 = new { value = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") },//DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")
        //        //        thing3 = new { value = "测试" },
        //        //        phone_number8 = new { value = "18768176955" },
        //        //        phrase10 = new { value = "新月小区" },
        //        //    }
        //        //});
        //        var request = (HttpWebRequest)WebRequest.Create(_url);
        //        request.Method = "POST";
        //        request.ContentType = "application/json;charset=UTF-8";
        //        byte[] byteData = Encoding.UTF8.GetBytes(jsonParam);
        //        int length = byteData.Length;
        //        request.ContentLength = length;
        //        Stream writer = request.GetRequestStream();
        //        writer.Write(byteData, 0, length);
        //        writer.Close();
        //        var response = (HttpWebResponse)request.GetResponse();
        //        responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();


        //        //JavaScriptSerializer js = new JavaScriptSerializer();   //实例化一个能够序列化数据的类
        //        //AccessTokenModel_Err ErrInfo = js.Deserialize<AccessTokenModel_Err>(responseString);


        //        //AccessTokenModel_Err ErrInfo = (AccessTokenModel_Err)JsonConvert.DeserializeObject(responseString);
        //        //res.message = ErrInfo.errmsg;
        //        //if (ErrInfo.errcode == 0)
        //        //    res.state = true;
        //        //return responseString.ToString();
        //        result.errcode = 0;
        //        result.errmsg = "";

        //        //lst.access_token = access_token;
        //        //lst.expires_in = expires_in;
        //        result.data = responseString;
        //        result.totalrecords = 0;
        //        return result;
        //    }
        //    catch (Exception ex)
        //    {
        //        result.errcode = 0;
        //        result.errmsg = "";

        //        //lst.access_token = access_token;
        //        //lst.expires_in = expires_in;
        //        result.data = responseString;
        //        result.totalrecords = 0;
        //        return result;
        //    }
        //    //return Json(res, JsonRequestBehavior.AllowGet);
        //}
        //#endregion

        #region 微信小程序发送消息
        [HttpPost]
        [Route("PostMessageInfo")]
        //访客到访申请审核通知
        public ResponseMessage PostMessageInfo(wx_postmessage wx_message)
        {
            //AjaxResult res = new AjaxResult();
            //res.state = false;
            var responseString = "";
            ResponseMessage result = new ResponseMessage();
            try
            {
                //AccessTokenModel AccessTokenModel = xcx_Get_Token();//获取access_token
                string _url = string.Format("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={0}", wx_message.access_token);
                //json参数
                string jsonParam = Newtonsoft.Json.JsonConvert.SerializeObject(new
                {
                    touser = wx_message.touser,   //"o1nvI5Nngrq2hUI_17jue-erLplc",//用戶openid
                    template_id = "EpSqtSa2u9JhQY5MufKkQLLcxZiGxn3045sZz5",    // 模版template_id
                    page = wx_message.page,//"../visitorpetition/petition",
                    //miniprogram_state = "developer",
                    lang = "zh_CN",
                    data = new
                    {
                        thing1 = new { value = wx_message.thing1.ToString() },
                        time3 = new { value = wx_message.time3.ToString() },//DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")
                        thing4 = new { value = wx_message.thing4.ToString() },
                        phone_number2 = new { value = wx_message.phone_number2.ToString() },
                        thing5 = new { value = wx_message.thing5.ToString() },
                    }
                });
                var request = (HttpWebRequest)WebRequest.Create(_url);
                request.Method = "POST";
                request.ContentType = "application/json;charset=UTF-8";
                byte[] byteData = Encoding.UTF8.GetBytes(jsonParam);
                int length = byteData.Length;
                request.ContentLength = length;
                Stream writer = request.GetRequestStream();
                writer.Write(byteData, 0, length);
                writer.Close();
                var response = (HttpWebResponse)request.GetResponse();
                responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();


                //JavaScriptSerializer js = new JavaScriptSerializer();   //实例化一个能够序列化数据的类
                //AccessTokenModel_Err ErrInfo = js.Deserialize<AccessTokenModel_Err>(responseString);


                //AccessTokenModel_Err ErrInfo = (AccessTokenModel_Err)JsonConvert.DeserializeObject(responseString);
                //res.message = ErrInfo.errmsg;
                //if (ErrInfo.errcode == 0)
                //    res.state = true;
                //return responseString.ToString();
                result.errcode = 0;
                result.errmsg = "";

                //lst.access_token = access_token;
                //lst.expires_in = expires_in;
                result.data = responseString;
                result.total = 0;
                return result;
            }
            catch (Exception ex)
            {
                result.errcode = 0;
                result.errmsg = "";

                //lst.access_token = access_token;
                //lst.expires_in = expires_in;
                result.data = responseString;
                result.total = 0;
                return result;
            }
            //return Json(res, JsonRequestBehavior.AllowGet);
        }

        #endregion
        #region 微信小程序发送消息
        [HttpPost]
        [Route("PostMessageInfoConfirm")]

        /// <summary>
        /// 访客到访审核结果通知
        /// </summary>
        public ResponseMessage PostMessageInfoConfirm(wx_postmessageConfirm wx_message)
        {
            //AjaxResult res = new AjaxResult();
            //res.state = false;
            var responseString = "";
            ResponseMessage result = new ResponseMessage();
            try
            {
                //AccessTokenModel AccessTokenModel = xcx_Get_Token();//获取access_token
                string _url = string.Format("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token={0}", wx_message.access_token);
                //json参数
                string jsonParam = Newtonsoft.Json.JsonConvert.SerializeObject(new
                {
                    touser = wx_message.touser,   //"o1nvI5Nngrq2hUI_17jue-erLplc",//用戶openid
                    template_id = "6A9qvXlp_yQPLBfzvXXS01IBtdye4Mn3om-L5rXIAOI",    // 模版template_id
                    page = wx_message.page,//"../visitorpetition/petition",
                    //miniprogram_state = "developer",
                    lang = "zh_CN",
                    data = new
                    {
                        name6 = new { value = wx_message.name6.ToString() },
                        date4 = new { value = wx_message.date4.ToString() },//DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")
                        phrase1 = new { value = wx_message.phrase1.ToString() },
                        thing5 = new { value = wx_message.thing5.ToString() },
                        thing3 = new { value = wx_message.thing3.ToString() },
                    }
                });
                //string jsonParam = Newtonsoft.Json.JsonConvert.SerializeObject(new
                //{
                //    touser = "o1nvI5Nngrq2hUI_17jue-erLplc",//用戶openid
                //    template_id = "kkKUHjxPI-FRZ8Suz-yEkhLP8gj_zppsythKaMh4Y0c",    // 模版template_id
                //    page = "../visitorpetition/petition",
                //    //miniprogram_state = "developer",
                //    lang = "zh_CN",
                //    data = new
                //    {
                //        name1 = new { value = "张飞" },
                //        time2 = new { value = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") },//DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")
                //        thing3 = new { value = "测试" },
                //        phone_number8 = new { value = "18768176955" },
                //        phrase10 = new { value = "新月小区" },
                //    }
                //});
                var request = (HttpWebRequest)WebRequest.Create(_url);
                request.Method = "POST";
                request.ContentType = "application/json;charset=UTF-8";
                byte[] byteData = Encoding.UTF8.GetBytes(jsonParam);
                int length = byteData.Length;
                request.ContentLength = length;
                Stream writer = request.GetRequestStream();
                writer.Write(byteData, 0, length);
                writer.Close();
                var response = (HttpWebResponse)request.GetResponse();
                responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();


                //JavaScriptSerializer js = new JavaScriptSerializer();   //实例化一个能够序列化数据的类
                //AccessTokenModel_Err ErrInfo = js.Deserialize<AccessTokenModel_Err>(responseString);


                //AccessTokenModel_Err ErrInfo = (AccessTokenModel_Err)JsonConvert.DeserializeObject(responseString);
                //res.message = ErrInfo.errmsg;
                //if (ErrInfo.errcode == 0)
                //    res.state = true;
                //return responseString.ToString();
                result.errcode = 0;
                result.errmsg = "";

                //lst.access_token = access_token;
                //lst.expires_in = expires_in;
                result.data = responseString;
                result.total = 0;
                return result;
            }
            catch (Exception ex)
            {
                result.errcode = 0;
                result.errmsg = "";

                //lst.access_token = access_token;
                //lst.expires_in = expires_in;
                result.data = responseString;
                result.total = 0;
                return result;
            }
            //return Json(res, JsonRequestBehavior.AllowGet);
        }
        #endregion

    }
}
